/*  
 *  --[Ag_12] - Reading the Weather station at Agriculture v20 board-- 
 *  
 *  Explanation: Turn on the Agriculture v20 board and read the 
 *  Weather station on it once every second
 *  
 *  Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details. 
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           0.1 
 *  Design:            David Gascón 
 *  Implementation:    Manuel Calahorra
 */

#include <WaspSensorAgr_v20.h>

// Variable to store the anemometer value
float anemometer;

// Variable to store the pluviometer value
float pluviometer;

// Variable to store the vane value
int vane;

void setup()
{
  // Turn on the USB and print a start message
  USB.ON();
  USB.println(F("start"));
  delay(100);

  // Turn on the sensor board
  SensorAgrv20.ON();
  
  // Turn on the RTC
  RTC.ON();
  
}
 
void loop()
{
  // Part 1: Sensor reading
  // Turn on the sensor and wait for stabilization and response time
  SensorAgrv20.setSensorMode(SENS_ON, SENS_AGR_ANEMOMETER);
  delay(10);
  
  // Read the anemoemter sensor 
  anemometer = SensorAgrv20.readValue(SENS_AGR_ANEMOMETER);
  
  // Read the pluviometer sensor 
  pluviometer = SensorAgrv20.readValue(SENS_AGR_PLUVIOMETER);

  // Read the vane sensor 
  vane = SensorAgrv20.readValue(SENS_AGR_VANE);

  // Turn off the sensor
  SensorAgrv20.setSensorMode(SENS_OFF, SENS_AGR_ANEMOMETER);
  
  // Part 2: USB printing
  // Print the weather values through the USB
  USB.print(F("Pluviometer: "));
  USB.print(pluviometer);
  USB.println(F("mm"));
  USB.print(F("Anemometer: "));
  USB.print(anemometer);
  USB.println(F("km/h"));
  USB.print(F("Vane: "));
  switch(SensorAgrv20.vaneDirection)
  {
    case  SENS_AGR_VANE_N   :  USB.println("N");
                               break;
    case  SENS_AGR_VANE_NNE :  USB.println("NNE");
                               break;
    case  SENS_AGR_VANE_NE  :  USB.println("NE");
                               break;
    case  SENS_AGR_VANE_ENE :  USB.println("ENE");
                               break;
    case  SENS_AGR_VANE_E   :  USB.println("E");
                               break;
    case  SENS_AGR_VANE_ESE :  USB.println("ESE");
                               break;
    case  SENS_AGR_VANE_SE  :  USB.println("SE");
                               break;
    case  SENS_AGR_VANE_SSE :  USB.println("SSE");
                               break;
    case  SENS_AGR_VANE_S   :  USB.println("S");
                               break;
    case  SENS_AGR_VANE_SSW :  USB.println("SSW");
                               break;
    case  SENS_AGR_VANE_SW  :  USB.println("SW");
                               break;
    case  SENS_AGR_VANE_WSW :  USB.println("WSW");
                               break;
    case  SENS_AGR_VANE_W   :  USB.println("W");
                               break;
    case  SENS_AGR_VANE_WNW :  USB.println("WNW");
                               break;
    case  SENS_AGR_VANE_NW  :  USB.println("WN");
                               break;
    case  SENS_AGR_VANE_NNW :  USB.println("NNW");
                               break;
  }

  
  delay(1000);
}
